package com.szlanyou.thirdsdk.retrofit.callback;

import android.view.View;

import com.szlanyou.thirdsdk.retrofit.callback.IHttpResultHandler;

/**
 * @author 陈章
 * create at 2021/7/8 17:03
 * desc:
 * 传入点击的View至网络请求回调监听器，对View进行锁定，防止用户重复点击。
 */
public abstract  class ClickViewRelatedHttpResultHandler<T> extends IHttpResultHandler<T> {
    /**
     * 点击发动网络请求的View
     */
    private View clickView;

    public ClickViewRelatedHttpResultHandler(View clickView) {
        this.clickView = clickView;
    }

    public ClickViewRelatedHttpResultHandler() {
    }

    @Override
    public void onStart(String requestPageFlag,String requestCode) {
        if (clickView != null) {
            clickView.setEnabled(false);
        }
    }

    @Override
    public void onCancel(String requestPageFlag,String requestCode) {
        if (clickView != null) {
            clickView.setEnabled(true);
        }
    }

    @Override
    public void onComplete(boolean causeByError) {
        if (clickView != null) {
            clickView.setEnabled(true);
        }
    }

}